<template>
  <el-carousel height="auto" style="border-radius: 10px">
    <el-carousel-item style="height: auto">
      <img src="@/static/image/banner_01.jpg" alt="" />
    </el-carousel-item>
    <el-carousel-item style="height: auto">
      <img src="@/static/image/banner_02.jpg" alt="" />
    </el-carousel-item>
    <el-carousel-item style="height: auto">
      <img src="@/static/image/banner_03.jpg" alt="" />
    </el-carousel-item>
  </el-carousel>
  <div>
    <el-row class="mt-5 mb-5 classify">
      <el-col
        :span="8"
        v-for="item in classifyList"
        :key="item.id"
        @click="handleClick(item)"
      >
        <el-card
          @mouseover="handleMouseover(item)"
          @mouseout="handleMouseout(item)"
          :class="{ 'hover-class': item.isHovering }"
        >
          <div class="classify-item">
            <img :src="item.img_url" alt="" />
            <div>{{ item.title }}</div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import { useRouter } from "#app";
import { useRuntimeConfig } from "nuxt/app";
const router = useRouter();
let classifyList = ref([]);
const data: any = await useServerRequest(
  "get-classification-list/",
  {
    query: { page_size: 10, page: 1, total: 0, type: 0 },
  },
  { method: "get" }
);
data.results.forEach((item: any) => {
  item.isHovering = false;
});
classifyList.value = data ? data.results : [];

// useFetch("http://338116ilpx21.vicp.fun/api/get-classification-list/", {
//   query: { page_size: 10, page: 1, total: 0, type: 0 },
//   method: "get",
// }).then((res: any) => {
//   console.log("----------------");
//   console.log(res.data.value.results);
//   console.log("----------------");
// });
const handleMouseover = (item: any) => {
  item.isHovering = true;
};
const handleMouseout = (item: any) => {
  item.isHovering = false;
};
const handleClick = (item: any) => {
  router.push(`/resource?id=${item.id}`);
};
</script>

<style scoped lang="scss">
.el-card {
  border-radius: 0px;
  box-shadow: none;
  background: #f8fafe;
}

.classify-item {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 50px 0;
  cursor: pointer;
  img {
    width: 60px;
    height: 60px;
    margin-bottom: 20px;
  }
}

.hover-class {
  text-decoration: none;
  font-size: 16px;
  color: #000000;
  background-repeat: no-repeat;
  background-position: center 78px;
  box-shadow: 0 30px 28px -18px rgba(0, 0, 0, 0.26);
  transform: translate(0, -4px);
}
</style>
